<template>
    <div>
    <div class="outmain ba_f">
        <div class="shuju_title mar_b20">
            <div class="shuju_title_text">
                <span>订单提醒</span>
            </div>
        </div>
        <el-form ref="form" :model="form" label-width="180px">
            <el-form-item label="后台语音提醒" :required="true">
                <el-radio-group v-model="form.voiceOpen">
                    <el-radio label="1">开启</el-radio>
                    <el-radio label="2">关闭</el-radio>
                </el-radio-group>
                <div class="yb_margin lh16">如需开启后台语音提醒，需先在服务器开启定时任务才能使用.</div>
            </el-form-item>
        </el-form>
    </div>
        <div class="mar_t20 ba_f pad_20 t_c">
            <el-button type="primary" @click="submitForm">保存</el-button>
        </div>
    </div>
</template>
<script>
    import {getConfig,postConfig} from "@/api/setup";

    export default {
        created() {
            this.bus.$emit('loading', true);
            this.init();
        },
        data() {
            return {
                form: {
                    voiceOpen:'1',
                },
            }
        },
        methods: {
            async init() {
                const {data} = await getConfig({ident: 'voice'});
                if(data.voiceOpen){
                    this.form = Object.assign({}, data);
                }
                this.bus.$emit('loading', false)
            },
            submitForm() {
                this.$refs["form"].validate(async (valid) => {
                    if (valid) {
                        this.form.ident = 'voice'
                        this.form.identName = '语音提醒设置'
                        const {msg} = await postConfig(this.form);
                        this.$baseMessage(msg, "success");
                        this.init();
                    } else {
                        return false;
                    }
                });
            },
        }
    }
</script>
